﻿@model ExportFileDetailsModel

@{
	var downloadString = T("Common.Download").Value;
	var allStoresString = T("Admin.Common.StoresAll").Value;
	var hasExportFiles = Model.ExportFiles.Any();
	var hasPublicFiles = Model.PublicFiles.Any();
}

<div sm-if="!hasExportFiles && !hasPublicFiles" class="alert alert-info">
    @T("Common.NoFilesAvailable")
</div>
<div attr-class='(hasExportFiles && hasPublicFiles, "mb-4")'>
	@foreach (var grp in Model.ExportFiles.OrderBy(x => x.DisplayOrder).GroupBy(x => x.DisplayOrder))
	{
		foreach (var file in grp)
		{
			<div class="py-1">
				<span class="badge @(file.RelatedType.HasValue ? "badge-secondary" : "badge-info")">
					<file-icon file-extension="@file.File.Extension" />
					@(file.Label.HasValue() ? file.Label : file.File.Extension.EmptyNull().ToLower().TrimStart('.'))
				</span>
				<a asp-action="DownloadExportFile" asp-route-id="@Model.Id" asp-route-name="@file.File.Name" asp-route-isDeployment="@Model.IsForDeployment" title="@downloadString" download>
					@file.FileRootPath
				</a>
			</div>
		}
	}
</div>
<div>
    @foreach (var grp in Model.PublicFiles.OrderBy(x => x.StoreId).GroupBy(x => x.StoreId))
	{
		var storeName = grp.First().StoreName;
		<div class="mt-3">
			<div>
				<span class="fs-h6 fwm">@T("Admin.Common.PublicFiles")</span>
				<span class="smaller">(@(storeName.HasValue() ? storeName : allStoresString))</span>
			</div>
			@foreach (var file in grp)
			{
				<div class="py-1 copy-to-clipboard">
					<div class="hstack gap-1">
						<span class="badge @(file.RelatedType.HasValue ? "badge-secondary" : "badge-success")">
							<file-icon file-extension="@file.File.Extension" />
							@(file.Label.HasValue() ? file.Label : file.File.Extension.EmptyNull().ToLower().TrimStart('.'))
						</span>
                        <a href="@file.FileUrl" title="@downloadString" download>@file.FileUrl</a>
                        <button type="button" class="btn btn-sm btn-flat btn-light btn-clipboard" data-copy="@file.FileUrl">
                            <bootstrap-icon name="clipboard" />
                        </button>
					</div>
				</div>
			}
		</div>
	}
</div>